package com.zuozuo.thread;

public class Demo2 {
    private static int ticketNums = 50;

    public static void main(String[] args) {
        Runnable runnable = () -> {
            while (true) {
                if (ticketNums <= 0) {
                    break;
                }
                System.out.println(Thread.currentThread().getName()+"：抢到了第"+ticketNums+"张票");
                ticketNums--;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        new Thread(runnable,"张三").start();
        new Thread(runnable,"李四").start();
        new Thread(runnable,"王五").start();


    }
}
